from flask import *
user = Blueprint("goods",__name__)
app = Flask(__name__)

users = [
    {"name":"Tom","id":0},
    {"name":"Jie","id":1},
    {"name":"Fu" ,"id":2}
]

@user.route("/",methods=["GET"])
def show_list():
    return users

@user.route("/add/<name>/<int:id>",methods=["POST"])
def add_list(name,id):
    users.append({"name":name ,"id":id})
    return users

@user.route("/del/<int:id>",methods=["DELETE"])
def del_list(id):
    for item in users:
        if item["id"] == id:
            users.remove(item)
    return users

@user.route("/che/<int:id>",methods=["GET"])
def che_list(id):
    for item in users:
        if item["id"] == id:
            return f"""name: {item["name"]}, id: {id}"""
    return f"id:{id}不存在"

@user.route("/cor/<name>/<int:id>",methods=["PUT"])
def cor_list(name,id):
    for item in users:
        if item["name"] == name:
            item["id"] = id
            return users
        if item["id"] == id:
            item["name"] = name
            return users
    else:
        return f"你输入的name:{name}、id:{id}均不存在"




if __name__ == "__main__":
    app.register_blueprint(user)
    app.run()